<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateInverterDatas extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        if(!Schema::hasTable('inverter_datas')) {
            Schema::create('inverter_datas', function (Blueprint $table) {
                $table->increments('id');
                $table->integer('device_id');
                $table->integer('site_id');
                $table->integer('user_id');

                //device params
                $table->double('DCU1');
                $table->double('DCI1');
                $table->double('DCU2')->nullable();
                $table->double('DCI2')->nullable();
                $table->double('DCU3')->nullable();
                $table->double('DCI3')->nullable();
                $table->double('DCU4')->nullable();
                $table->double('DCI4')->nullable();

                $table->double('ACUA')->nullable();
                $table->double('ACIA')->nullable();
                $table->double('ACUB')->nullable();
                $table->double('ACIB')->nullable();
                $table->double('ACUC')->nullable();
                $table->double('ACIC')->nullable();

                $table->double('IVTemp');
                $table->double('TotGenCap');
                $table->integer('IVStatus');
                $table->integer('IVError');
                $table->integer('IVMode');
                $table->double('FR');

                $table->integer('IVRun')->nullable();
                $table->integer('MonthGenCap')->nullable();
                $table->integer('LastMonthGenCap')->nullable();
                $table->double('DayGenCap')->nullable();
                $table->double('LastDayGenCap')->nullable();

                $table->double('PowerLimitPercent')->nullable();
                $table->integer('ActivePower')->nullable();
                $table->integer('ReactivePower')->nullable();
                $table->integer('ApparentPower')->nullable();
                $table->double('PowerFactor')->nullable();

                $table->integer('IVType')->nullable();
                $table->dateTime('EventTime')->nullable();
                $table->integer('EventType')->nullable();


                $table->timestamps();
                $table->softDeletes();
            });
        }
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::drop('inverter_datas');
    }
}
